/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       gamestatemanager.h
 * Author:     karooolek
 * Created on: 2009-04-09
 *
 **********************************************************************************************************************/

#ifndef GAMESTATEMANAGER_H_
#define GAMESTATEMANAGER_H_

#include "gamestate.h"
#include "../common.h"

namespace mGameEngine
{
namespace Game
{

/**
 * Game state manager.
 * Game state manager organizes game states logic as stack.
 * Application can push and pop various states on the stack.
 * Game state, which is on top of stack, is active, and it's 
 * loop will be processed.
 * Game state manager is fully responsible for game states 
 * life cycle.
 */
class GameStateManager
{
protected:
    /**
     * Game states stack.
     */
    List<GameState *> _gameStates;

    /**
     * Game states pushes queue.
     */
    List<GameState *> _push;

    /**
     * Game state pops queue.
     */
    uint8 _pop;

public:
    /**
     * Create new game state manager.
     */
    GameStateManager();

    /**
     * Destroy game state manager.
     */
    virtual ~GameStateManager();

    /**
     * Get active game state.
     * @return active game state.
     */
    virtual GameState *getActiveGameState() const;

    /**
     * Set active game state.
     * Current active game state will be popped
     * and new game state will be pushed on top of
     * game states stack.
     * Game state will be queued and set after loops end.
     * @param gameState game state.
     */
    virtual void setGameState(GameState *gameState);

    /**
     * Push game state on top of game states stack.
     * Game state will be queued become active after loops end.
     * @param gameState new game state.
     */
    virtual void pushGameState(GameState *gameState);

    /**
     * Pop active game state from game states stack.
     * Game state will be queued and popped after loops end.
     */
    virtual void popGameState();

    /**
     * Game state manager main loop.
     */
    virtual void idle();

    /**
     * Game state manager draw loop.
     */
    virtual void draw() const;
};

}
}

#endif // GAMESTATEMANAGER_H_
